home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Internet / WWW / swish.11 / src / check.c next >
C/C++ Source or Header  |  1995-03-13  |  4KB  |  207 lines

  1. /*
  2. ** Copyright (C) 1995, Enterprise Integration Technologies Corp.        
  3. ** All Rights Reserved.
  4. ** Kevin Hughes, kevinh@eit.com 
  5. ** 3/11/94
  6. */
  7.  
  8. #include "swish.h"
  9. #include "check.h"
  10.  
  11. /* Check if a file with a particular suffix should be indexed
  12. ** according to the settings in the configuration file.
  13. */
  14.  
  15. int isoksuffix(filename, rulelist)
  16.      char *filename;
  17.      struct swline *rulelist;
  18. {
  19.     int badfile;
  20.     char *c, suffix[MAXSUFFIXLEN], checksuffix[MAXSUFFIXLEN];
  21.     struct swline *tmplist;
  22.  
  23.     tmplist = rulelist;
  24.         if (tmplist == NULL)
  25.                 return 1;
  26.     if ((c = (char *) strrchr(filename, '.')) == NULL)
  27.         return 0;
  28.  
  29.     badfile = 1;
  30.     strcpy(checksuffix, c + 1);
  31.         while (tmplist != NULL) {
  32.         if ((c = (char *) strrchr(tmplist->line, '.')) == NULL)
  33.             strcpy(suffix, tmplist->line);
  34.         else
  35.             strcpy(suffix, c + 1);
  36.                 if (lstrstr(suffix, checksuffix) && strlen(suffix) ==
  37.         strlen(checksuffix))
  38.                         badfile = 0;
  39.                 tmplist = tmplist->next;
  40.         }
  41.     return !(badfile);
  42. }
  43.  
  44. /* Check if a particular title should be ignored
  45. ** according to the settings in the configuration file.
  46. */
  47.  
  48. int isoktitle(title)
  49.      char *title;
  50. {
  51.         int badfile;
  52.         struct swline *tmplist;
  53.  
  54.         badfile = 0;
  55.         tmplist = titconlist;
  56.         while (tmplist != NULL) {
  57.                 if (lstrstr(title, tmplist->line)) {
  58.                         badfile = 1;
  59.                         break;
  60.                 }
  61.                 tmplist = tmplist->next;
  62.         }
  63.         if (badfile)
  64.                 return 0;
  65.         else
  66.                 return 1;
  67. }
  68.  
  69. /* Should a word be indexed? Consults the stopword hash list
  70. ** and checks if the word is of a reasonable length...
  71. ** If you have any good rules that can work with most languages,
  72. ** please let me know...
  73. */
  74.  
  75. int isokword(word)
  76.       char *word;
  77. {
  78.         int i, same, hasnumber, hasvowel, hascons,
  79.         numberrow, vowelrow, consrow;
  80.     char lastchar;
  81.  
  82.     if (word[0] == '\0')
  83.         return 0;
  84.  
  85.         if (isstopword(word))
  86.                 return 0;
  87.         if (strlen(word) < MINWORDLIMIT || strlen(word) > MAXWORDLIMIT)
  88.                 return 0;
  89.  
  90.     lastchar = ':';
  91.     same = 0;
  92.     hasnumber = hasvowel = hascons = 0;
  93.     numberrow = vowelrow = consrow = 0;
  94.     for (i = 0; word[i] != '\0'; i++) {
  95.         if (word[i] == lastchar) {
  96.             same++;
  97.             if (same > IGNORESAME)
  98.                 return 0;
  99.         }
  100.         else
  101.             same = 0;
  102.         if (isdigit(word[i])) {
  103.             hasnumber = 1;
  104.             numberrow++;
  105.             if (numberrow > IGNOREROWN)
  106.                 return 0;
  107.             vowelrow = 0;
  108.             consrow = 0;
  109.         }
  110.         else if (isvowel(word[i])) {
  111.             hasvowel = 1;
  112.             vowelrow++;
  113.             if (vowelrow > IGNOREROWV)
  114.                 return 0;
  115.             numberrow = 0;
  116.             consrow = 0;
  117.         }
  118.         else if (!ispunct(word[i])) {
  119.             hascons = 1;
  120.             consrow++;
  121.             if (consrow > IGNOREROWC)
  122.                 return 0;
  123.             numberrow = 0;
  124.             vowelrow = 0;
  125.         }
  126.         lastchar = word[i];
  127.     }
  128.  
  129.     if (IGNOREALLV)
  130.         if (hasvowel && !hascons)
  131.             return 0;
  132.     if (IGNOREALLC)
  133.         if (hascons && !hasvowel)
  134.             return 0;
  135.     if (IGNOREALLN)
  136.         if (hasnumber && !hasvowel && !hascons)
  137.             return 0;
  138.  
  139.     return 1;
  140. }
  141.  
  142. /* Does a word have valid characters?
  143. */
  144.  
  145. int hasokchars(word)
  146.      char *word;
  147. {
  148.     int i, j;
  149.     char c;
  150.  
  151.     c = word[strlen(word) - 1];
  152.     for (i = j = 0; BEGINCHARS[i] != '\0'; i++)
  153.         if (word[0] == BEGINCHARS[i])
  154.             j++;
  155.     if (!j)
  156.         return 0;
  157.     for (i = j = 0; ENDCHARS[i] != '\0'; i++)
  158.         if (c == ENDCHARS[i])
  159.             j++;
  160.     if (!j)
  161.         return 0;
  162.     for (i = 0; word[i] != '\0'; i++)
  163.         for (j = 0; WORDCHARS[j] != '\0'; j++)
  164.             if (word[i] == WORDCHARS[j])
  165.                 return 1;
  166.     return 0;
  167. }
  168.  
  169. /* Is a letter a vowel?
  170. */
  171.  
  172. int isvowel(c)
  173.      char c;
  174. {
  175.     if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
  176.         return 1;
  177.     return 0;
  178. }
  179.  
  180. /* This checks is a filename has one of the following suffixes:
  181. ** "htm", "HTM", "html", "HTML", "shtml", "SHTML".
  182. */
  183.  
  184. int ishtml(filename)
  185.      char *filename;
  186. {
  187.     char *c, suffix[MAXSUFFIXLEN];
  188.  
  189.     c = (char *) strrchr(filename, '.');
  190.  
  191.     if (c == NULL)
  192.         return 0;
  193.     strcpy(suffix, c + 1);
  194.     if (suffix[0] == '\0')
  195.         return 0;
  196.  
  197.     if (!strncmp(suffix, "htm", 3))
  198.         return 1;
  199.     else if (!strncmp(suffix, "HTM", 3))
  200.         return 1;
  201.     else if (!strncmp(suffix, "shtml", 5))
  202.         return 1;
  203.     else if (!strncmp(suffix, "SHTML", 5))
  204.         return 1;
  205.     return 0;
  206. }
  207.